home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 422 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.1 KB

  1. Path: yrkpa.kias.com!not-for-mail
  2. From: glynis@yrkpa.kias.com (John Flinchbaugh)
  3. Newsgroups: comp.lang.c
  4. Subject: mixing enums and integers
  5. Date: 5 Jan 1996 02:15:32 -0500
  6. Organization: Keystone Information Access Systems
  7. Message-ID: <4cij6k$dvb@yrkpa.kias.com>
  8. NNTP-Posting-Host: yrkpa.kias.com
  9. X-Newsreader: NewsWerthy 2.02 (unregistered)
  10.  
  11. the faq states that mixing enums and ints is legal, but poor style.
  12.  
  13. i'd like to use enums to organize my constants, like this:
  14.  
  15.     enum DIRECT {UP=72,LEFT=75,RIGHT=77,DOWN=80};
  16.     int key;
  17.     getch();     /* dos code to get the second byte of 2-byte */
  18.     key=getch();     /* key codes from keyboard             */
  19.     if (key==UP) printf("up");
  20.     ...
  21.  
  22. now this should work, but it's poor style, right?
  23. would casting it be more proper:
  24.  
  25.     if ((enum DIRECT) key==up) ...
  26.  
  27. also, can you typedef enums?  if so, how?
  28.     
  29. -- 
  30. _____________________}John Flinchbaugh{______________________
  31. | -> glynis@yrkpa.kias.com <-      jmflinch@cs.millersv.edu |
  32. |    glynis@bitbytes.com     jmf89784@marauder.millersv.edu |
  33. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  34.